package com.mkj.component;

import javax.swing.*;
import java.awt.*;

/**
 * @Author Arrebol
 * @Date 2024/8/4 10:18
 * @Project graphical programming
 * @Description：
 * 这里测试基本组件
 */
public class BasicComponentsDemo {
    Frame frame=new Frame("这里测试基本组件");
    TextArea textArea=new TextArea(5,20);
    Choice colorChoicer = new Choice();
    CheckboxGroup checkboxGroup=new CheckboxGroup();
    Checkbox male = new Checkbox("男",checkboxGroup,true);
    Checkbox female = new Checkbox("女",checkboxGroup,false);
    Checkbox isMarried = new Checkbox("是否已婚",checkboxGroup,false);
    TextField textField=new TextField(50);
    Button OK = new Button("确认");
    List colorList = new List(6,true);

    public static void main(String[] args) {
        new BasicComponentsDemo().init();
    }

    /**
     * 组装界面
     */
    public void init(){
        //组装底部
        Box bBox = Box.createHorizontalBox();
        bBox.add(textField);
        bBox.add(OK);
        frame.add(bBox,BorderLayout.SOUTH);

        //组装选择部分
        colorChoicer.add("红色");
        colorChoicer.add("蓝色");
        colorChoicer.add("绿色");
        Box cBox = Box.createHorizontalBox();
        cBox.add(colorChoicer);
        cBox.add(male);
        cBox.add(female);
        cBox.add(isMarried);

        //组装文本域与选择部分
        Box topLeft = Box.createVerticalBox();
        topLeft.add(textArea);
        topLeft.add(cBox);

        //组装顶部左边以及列表框
        colorList.add("红色");
        colorList.add("蓝色");
        colorList.add("绿色");
        Box top = Box.createHorizontalBox();
        top.add(topLeft);
        top.add(colorList);

        frame.add(top);

        frame.pack();
        frame.setVisible(true);
    }
}
